package com.nike.app;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileReader;
import java.security.MessageDigest;
import java.util.Calendar;
import java.util.Formatter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.TimeZone;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import com.nike.test.TestUUID;

public class Zi {
	public static String getDeviceId() {
        StringBuilder v0 = new StringBuilder("0500");
        try {
            HashMap v1 = new HashMap();
            b(((Map)v1), "BBSC", "Android");
            b(((Map)v1), "CLIENT_TIME", c());
            b(((Map)v1), "AFPID", b());
            b(((Map)v1), "MACA", TestUUID.getMac());
            b(((Map)v1), "BMACA", TestUUID.getMac());
            b(((Map)v1), "ASL", "9");
            b(((Map)v1), "ABN", "9.1.0."+new Random().nextFloat()+TestUUID.getABN());
            a(((Map)v1));
            b(((Map)v1), "ANID", TestUUID.getAndroidId());
            b(((Map)v1), "AMID", TestUUID.getAndroidId());
            b(((Map)v1), "ADSV", "9.0.1");
            b(((Map)v1), "ADM", "LLD-AL"+new Random().nextInt(1000));
            b(((Map)v1), "ADLO", "zh");
            v0.append(a(C(((Map)v1))));
        }
        catch(Throwable v4) {
            throw v4;
        }

        return v0.toString();
    }
	private static String a(String arg2) {
		System.out.println(arg2);
        String v0 = "";
        if(arg2 != null) {
            try {
                arg2 = b(arg2.getBytes("utf-8"));
            }
            catch(Exception e1) {
            
            }
        }
        else {
        	arg2 = v0;
        }

        return arg2;
    }
	 private static String b(byte[] arg8) {
	        String v8_2;
	        byte[] v0 = new byte[]{16, -59, 20, -5, -54, -85, 110, 61, -51, -99, 70, -78, 11, -44, 3, 5, -120, 58, -14, 74, 13, -122, 35, 120, 14, -60, 67, 73, -58, -90, 42, 0x70};
	        String v1 = "";
	        int v2 = 16;
	        try {
	            byte[] v3 = new byte[v2];
	            new Random().nextBytes(v3);
	            ByteArrayOutputStream v4 = new ByteArrayOutputStream();
	            v4.write("0500".getBytes());
	            v4.write(arg8);
	            int v8 = v4.size() % v2 == 0 ? 0 : 16 - v4.size() % v2;
	            v4.write(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, v8);
	            Cipher v8_1 = Cipher.getInstance("AES/CBC/NoPadding");
	            v8_1.init(1, new SecretKeySpec(v0, "AES"), new IvParameterSpec(v3));
	            arg8 = v8_1.doFinal(v4.toByteArray());
	            ByteArrayOutputStream v0_1 = new ByteArrayOutputStream();
	            v0_1.write(v3);
	            v0_1.write(arg8);
	            v8_2 = new String(ad(v0_1.toByteArray()));
	        }
	        catch(Throwable e1) {
	            v8_2 = v1;
	        }

	        return v8_2;
	    }
	 private static byte[] ad(byte[] arg11) {
		 byte[] returnBy = null;
	        int v11;
	        int v8;
	        byte[] v0 = new byte[]{65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 0x4F, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 120, 0x79, 0x7A, 0x30, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 0x2F};
	        if(arg11 != null) {
	            int v1 = arg11.length;
	            if(v1 != 0) {
	                int v2 = v1 / 3;
	                int v4 = 0;
	                int v3 = v1 % 3 != 0 ? 1 : 0;
	                byte[] v3_1 = new byte[(v3 + v2) * 4];
	                int v6 = 0;
	                int v7 = 0;
	                while(v4 < v2) {
	                    v8 = v6 + 1;
	                    int v9 = v8 + 1;
	                    v6 = (arg11[v6] & 0xFF) << 16 | (arg11[v8] & 0xFF) << 8;
	                    v8 = v9 + 1;
	                    v6 |= arg11[v9] & 0xFF;
	                    v9 = v7 + 1;
	                    v3_1[v7] = v0[v6 >> 18 & 0x3F];
	                    v7 = v9 + 1;
	                    v3_1[v9] = v0[v6 >> 12 & 0x3F];
	                    v9 = v7 + 1;
	                    v3_1[v7] = v0[v6 >> 6 & 0x3F];
	                    v7 = v9 + 1;
	                    v3_1[v9] = v0[v6 & 0x3F];
	                    ++v4;
	                    v6 = v8;
	                }

	                v2 *= 3;
	                if(v2 < v1) {
	                    v4 = v6 + 1;
	                    v6 = (arg11[v6] & 0xFF) << 16;
	                    v8 = v7 + 1;
	                    v3_1[v7] = v0[v6 >> 18 & 0x3F];
	                    byte v5 = 61;
	                    if(v2 + 1 < v1) {
	                        v11 = (arg11[v4] & 0xFF) << 8 | v6;
	                        v1 = v8 + 1;
	                        v3_1[v8] = v0[v11 >> 12 & 0x3F];
	                        v2 = v1 + 1;
	                        v3_1[v1] = v0[v11 >> 6 & 0x3F];
	                    }
	                    else {
	                        v11 = v8 + 1;
	                        v3_1[v8] = v0[v6 >> 12 & 0x3F];
	                        v2 = v11 + 1;
	                        v3_1[v11] = v5;
	                    }

	                    v3_1[v2] = v5;
	                }

	                returnBy = v3_1;
	            }
	        }
	        return returnBy;
	    }
	private static void a(Map arg6) {
        String v5;
        String v1;
        BufferedReader v0;
        try {
            v0 = new BufferedReader(new FileReader("/proc/version"), 0x100);
        }
        catch(Throwable e1) {
            return;
        }

        try {
            v1 = v0.readLine();
            v0.close();
            Matcher v0_1 = Pattern.compile("\\w+\\s+\\w+\\s+([^\\s]+)\\s+\\(([^\\s@]+(?:@[^\\s.]+)?)[^)]*\\)\\s+\\((?:[^(]*\\([^)]*\\))?[^)]*\\)\\s+([^\\s]+)\\s+(?:PREEMPT\\s+)?(.+)").matcher(((CharSequence)v1));
            if(v0_1.matches()) {
                int v2 = 4;
                if(v0_1.groupCount() >= v2) {
                    v1 = v0_1.group(1);
                    int v4 = 50;
                    if(v1 == null || v1.length() <= v4) {
                        v5 = "AKV";
                    }
                    else {
                        v5 = "AKV";
                        v1 = v1.substring(0, v4);
                    }

                    b(arg6, v5, v1);
                    v1 = v0_1.group(2);
                    if(v1 == null || v1.length() <= v4) {
                        v5 = "AKID";
                    }
                    else {
                        v5 = "AKID";
                        v1 = v1.substring(0, v4);
                    }

                    b(arg6, v5, v1);
                    v1 = v0_1.group(3);
                    if(v1 == null || v1.length() <= v4) {
                        v5 = "AKBN";
                    }
                    else {
                        v5 = "AKBN";
                        v1 = v1.substring(0, v4);
                    }

                    b(arg6, v5, v1);
                    String v0_2 = v0_1.group(v2);
                    if(v0_2 != null && v0_2.length() > v4) {
                        b(arg6, "AKD", v0_2.substring(0, v4));
                        return;
                    }

                    b(arg6, "AKD", v0_2);
                }
            };
        }
        catch(Throwable v6) {
            try {
                v0.close();
                throw v6;
            }
            catch(Throwable e1) {
                return;
            }
        }
    }
	private static String a(byte[] arg3) {
        try {
            MessageDigest v0 = MessageDigest.getInstance("MD5");
            v0.update(arg3);
            arg3 = v0.digest();
            StringBuffer v0_1 = new StringBuffer();
            int v1;
            for(v1 = 0; v1 < arg3.length; ++v1) {
                v0_1.append(Integer.toHexString(arg3[v1] & 0xFF));
            }

            return v0_1.toString();
        }
        catch(Throwable e2) {
            return null;
        }
    }
	private static void b(Map arg1, String arg2, String arg3) {
        if(arg2 != null && arg3 != null && arg3.length() > 0) {
            arg1.put(arg2, arg3);
        }
    }
	private static String c() {
        try {
            Calendar v0 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            return String.format("%04d %02d %02d %02d:%02d:%02d.%03d", Integer.valueOf(v0.get(1)), Integer.valueOf(v0.get(2) + 1), Integer.valueOf(v0.get(5)), Integer.valueOf(v0.get(11)), Integer.valueOf(v0.get(12)), Integer.valueOf(v0.get(13)), Integer.valueOf(v0.get(14)));
        }
        catch(Throwable e2) {
            return null;
        }
    }
	private static String b() {
        try {
//            return a(Build.FINGERPRINT.getBytes("utf-8"));
        	return a(UUID.randomUUID().toString().substring(0, 13).replace("-", "").getBytes("utf-8"));
        }
        catch(Throwable e2) {
            return null;
        }
    }
	private static void a(Formatter arg5, String arg6) {
        arg5.format("%04x", Integer.valueOf(arg6.length()));
        arg5.format("%s", arg6);
    }
	private static String C(Map arg6) {
        StringBuilder v0 = new StringBuilder();
        if(arg6 == null) {
            v0.append("0");
        }
        else {
            Formatter v1 = new Formatter(((Appendable)v0));
            v1.format("%04x", Integer.valueOf(arg6.size()));
            Iterator v6 = arg6.entrySet().iterator();
            while(v6.hasNext()) {
                Object v2 = v6.next();
                a(v1, ((Entry)v2).getKey()+"");
                a(v1, ((Entry)v2).getValue()+"");
            }
        }
        return v0.toString();
    }
}
